package com.automation.autocode;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 
 * @author ren.bo2
 *
 */
@Configuration
@ComponentScan
public class WebConfig extends WebMvcConfigurerAdapter {
	//http://localhost:8080/mebyo/images/jslider.blue.png
	@Autowired
	Environment enviroment;

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		//		Properties props = System.getProperties(); //获得系统属性集    
		//		String osName = props.getProperty("os.name");
		//		if (osName.startsWith("Windows") || osName.startsWith("windows")) {
		//			registry.addResourceHandler("/images/**").addResourceLocations("file:" + enviroment.getProperty("windows.health.nfs.root.image") + "");
		//		} else {
		//			registry.addResourceHandler("/images/**").addResourceLocations("file:" + enviroment.getProperty("linux.health.nfs.root.image") + "");
		//		}
		//		registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
		//		registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
		//		registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
		super.addResourceHandlers(registry);
	}

	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/**").allowedOrigins("*").allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE").maxAge(3600).allowCredentials(true);
	}
}
